global input "Q:\dc1prhcmsas01\PU2\data - sas"
global temp "Q:\dc1prhcmsas01\PU2\temp_stata_wr"
global log "Q:\dc1prhcmsas01\PU2\Log - Stata WR"
global output "Q:\dc1prhcmsas01\PU2\data_stata_wr"
global graphs "Q:\dc1prhcmsas01\PU2\graphs_stata_wr"
global tables "Q:\dc1prhcmsas01\PU2\tables_stata_wr"

cd "Q:\dc1prhcmsas01\PU2\Code - Stata WR"

capture log close
log using "$log/6_fig_diff_distribution", replace

set scheme plotplain
graph set window fontface "Times New Roman"

*Program for connected plot by base pay
cap program drop plot_connect
program define plot_connect
args var sal sample name legend1 legend2 ylabel ytitle1 ytitle2
	graph twoway (connect `var' bin if salaried==`sal' & `sample'==0 , lc(black) mcolor(black)) ///
		(connect `var' bin if salaried==`sal' & `sample'==1, lc(maroon) mcolor(maroon) msymbol(D)), ///
		xline(455, lcolor(black)) xline(913, lcolor(red)) xtitle("Weekly Base Pay") xlabel(0(500)2500) ///
		l2title(`ytitle1') l1title(`ytitle2') ytitle("") ylabel(`ylabel') legend(order(1 "`legend1'" 2 "`legend2'") ring(0) position(5) col(2) region(lstyle(solid) lcolor(black) lwidth(thin)))
	graph export "$graphs/`name'.eps", replace
	graph export "$graphs/`name'.jpg", replace
end 

*Fig 1a:
use "$output\stayers_distribution_treat.dta", clear
keep if yr_month==mdy(04,01,2016) | yr_month==mdy(12,01,2016)

	*Calculate share and collapse by date
	bysort yr_month client_id salaried0: egen emp=sum(n)
	gen share=n/emp
	collapse (mean) share, by(yr_month salaried0 bin)
	drop if bin<=0 | bin>2500
	gen time=yr_month==mdy(12,01,2016)
	sum share if salaried==1 & time==0 & bin==913
	
	plot_connect share 1 time fig1a_average_distribution_salaried "April 2016" "December 2016" 0(0.01)0.03 "Share of Salaried Workers"
	plot_connect share 0 time fig1a_average_distribution_hourly "April 2016" "December 2016" 0(0.01)0.06 "Share of Hourly Workers"
	
	*Share pre and post in treated interval 
	preserve 
		gen treat=bin>=455 & bin<913
		keep if salaried0==1
		collapse (sum) share, by(yr_month treat)
		sum share if treat==1 & yr_month==mdy(04,01,2016)
		sum share if treat==1 & yr_month==mdy(12,01,2016)
	restore
	save "$output/fig1_distribution", replace
	
*Fig 1b:
	*Calculate difference in 2016
	drop yr_month
	reshape wide share, i(salaried bin) j(time)
	gen diff_share=share1-share0
	gen treat=1
	tempfile treat
	save `treat'

	*Calculate difference in 2014
	use "$output\stayers_distribution_control.dta", clear
	keep if yr_month==mdy(04,01,2014) | yr_month==mdy(12,01,2014)
	bysort yr_month client_id salaried0: egen emp=sum(n)
	gen share=n/emp
	collapse (mean) share, by(yr_month salaried0 bin)
	drop if bin<=0 | bin>2500
	gen time=yr_month==mdy(12,01,2014)
	drop yr_month
	reshape wide share, i(salaried bin) j(time)
	gen diff_share=share1-share0
	sum diff_share if salaried==1 & bin==913
	gen treat=0 
	append using `treat'
	
	plot_connect diff_share 1 treat fig1b_diff_distribution_salaried "2014" "2016" -0.005(0.0025)0.01 "Difference in Share of Salaried Workers" "Between April and December"
	plot_connect diff_share 0 treat fig1b_diff_distribution_hourly "2014" "2016" -0.005(0.0025)0.01 "Difference in Share of Hourly Workers" "Between April and December"
	
*Fig 1c:
	*Program for bar plot by base pay
	cap program drop plot_bar
	program define plot_bar
	args var sal ytitle name ylabel

		graph twoway (bar `var' bin if salaried==`sal', barwidth(20)), ///
		xline(455, lcolor(black)) xline(913, lcolor(red)) xline(693 853, lpattern(dot)) ///
		xlabel(0 455 693 853 913 2500, angle(45)) xtitle("Weekly Base Pay") ///
		ytitle(`ytitle') ylabel(`ylabel') legend(off)
		graph export "$graphs/`name'.eps", replace
		graph export "$graphs/`name'.jpg", replace

	end
	
	drop share0 share1
	reshape wide diff_share, i(salaried bin) j(treat)
	gen diff_diff=diff_share1-diff_share0
	
	plot_bar diff_diff 1 "Treatment Effect on Share of Salaried Workers" fig1c_diff_diff_distribution_salaried -0.005(0.0025)0.01
	plot_bar diff_diff 0 "Treatment Effect on Share of Hourly Workers" fig1c_diff_diff_distribution_hourly -0.005(0.0025)0.01
	
log close 